# # coding=UTF-8
# import datetime
# import os
# import random
# import time
#
# import requests
# from bs4 import BeautifulSoup
#
# # from common.fund_gp_dict import fund_gp_dict as f_dict
# from utils import doc_util
#
# base_path = os.path.join(os.getcwd().split('StockMonitor')[0] + 'StockMonitor')
# common_path = os.path.join(base_path, 'common')
#
# url = 'http://fund.eastmoney.com/js/fundcode_search.js'
# url1 = 'https://push2.eastmoney.com/api/qt/ulist.np/get?cb=jQuery18308106396323091587_1593671935494&fltt=2&invt=2&ut=267f9ad526dbe6b0262ab19316f5a25b&fields=f3,f12,f14&secids=1.600383,0.000656,1.600048,0.000002,0.000069,0.000671,0.001979,0.002146,1.601155,0.000961&_=1593671935724'
#
# fund_dict = {}
#
#
# def funds_detail_info():
#     fund_detail_file = open(os.path.join(base_path, 'common', 'funds', 'detail', '1.股票基金'), mode='a', encoding='utf-8')
#     flag = 0
#     for code in f_dict:
#         if code == '161837':
#             flag = 1
#         if flag:
#             fund_detail = detail_info(code)
#             fund_detail['up_time'] = str(int(round(time.time() * 1000)))
#             fund_detail_file.write(str(fund_detail) + '\n')
#     fund_detail_file.close()
#     # 删除路径下空文件
#     doc_util.del_blank_doc(os.path.join(base_path, 'common', 'funds', 'detail'))
#
#
# # 季度涨幅 url 地址
# # http://fundf10.eastmoney.com/jndzf_005968.html
# # http://fundf10.eastmoney.com/FundArchivesDatas.aspx?type=quarterzf&code=005968&rt=0.29795761120683595
#
#
# def detail_info(code):
#     print("获取基金详细信息")
#     # time_stamp = int(round(time.time() * 1000))
#     rt_list = ['0.7066729178833983', '0.9890302695875468', '0.3440840184855922', '0.0024700778759517705',
#                '0.004676314518826885', '0.32620867910252427']
#     year = str(datetime.datetime.now().year)
#     req_url = 'http://fundf10.eastmoney.com/FundArchivesDatas.aspx?type=jjcc&' \
#               'code=' + code + '&topline=20&year=' + year + '&month=&rt=' + rt_list[random.randint(0, 5)]
#
#     # a = 'var apidata={ content:"",arryear:[],curyear:2020};'
#     print(req_url)
#     resp = requests.get(req_url)
#     resp_content = str(resp.content.decode('utf-8'))
#     soup = BeautifulSoup(resp_content, 'html')  # html.parser是解析器，也可是lxml
#     detail_file = open(os.path.join(base_path, 'common', 'funds', 'detail', code), mode='w', encoding='utf-8')
#     fund_detail = {}
#     fund_detail[code] = {}
#     tbody_list = soup.select('tbody')
#     if len(tbody_list) == 0:
#         return fund_detail
#     for info in tbody_list[0].children:
#         info_contents = info.contents
#         contents_len = len(info_contents)
#         stock_detail = {}
#         if contents_len == 7:
#             stock_detail['code'] = info_contents[1].string
#             stock_detail['name'] = info_contents[2].string
#             stock_detail['ratio'] = info_contents[4].string
#             stock_detail['hold_hard'] = info_contents[5].string
#             stock_detail['market_v '] = info_contents[6].string
#             stock_detail['up_time'] = str(int(round(time.time() * 1000)))
#         elif contents_len == 9:
#             stock_detail['code'] = info_contents[1].string
#             stock_detail['name'] = info_contents[2].string
#             stock_detail['ratio'] = info_contents[6].string
#             stock_detail['hold_hard'] = info_contents[7].string
#             stock_detail['market_v '] = info_contents[8].string
#             stock_detail['up_time'] = str(int(round(time.time() * 1000)))
#         else:
#             print(info_contents)
#             print(contents_len)
#         detail_file.write(str(stock_detail) + '\n')
#         fund_detail[code][info_contents[0].string] = stock_detail
#     detail_file.close()
#     return fund_detail
#
#
# # 获取所有的股票型基金
# def get_info():
#     fund_file = open(os.path.join(base_path, 'common', 'funds', '1.股票基金'), mode='w', encoding='utf-8')
#     resp1 = requests.get(url)
#     resp1_content = str(resp1.content.decode('utf-8'))
#     fund_list = resp1_content.split('[[')[1].split(']]')[0]
#     # ["000001","HXCZHH","华夏成长混合","混合型","HUAXIACHENGZHANGHUNHE"]
#     for fund_str in fund_list.split('],['):
#         fund_str = fund_str.replace('\"', '')
#         fund_info_list = fund_str.split(',')
#         fund_dict[fund_info_list[0]] = {}
#         fund_dict[fund_info_list[0]]['name'] = fund_info_list[2]
#         fund_dict[fund_info_list[0]]['code'] = fund_info_list[0]
#         fund_dict[fund_info_list[0]]['type'] = fund_info_list[3]
#         fund_dict[fund_info_list[0]]['short_name'] = fund_info_list[1]
#         fund_dict[fund_info_list[0]]['full_name'] = fund_info_list[4]
#     for key in fund_dict:
#         fund_file.write(str(fund_dict[key]) + '\n')
#     fund_file.close()
#
#     # 更新 fund_dict
#     fund_file = open(os.path.join(common_path, 'fund_gp_dict.py'), mode='w', encoding='utf-8')
#     fund_file.write('# coding=UTF-8\n')
#     fund_file.write('fund_gp_dict = ')
#     fund_file.write(str(fund_dict))
#     fund_file.close()
#
#
# if __name__ == '__main__':
#     print("start")
#     # get_info()
#     # funds_detail_info()
#     detail_info('000001')
#     print('end')
